/* eslint-disable no-undef */

class Main{
    viewer;
    extension;
    modelUrls = [
        "https://www.aisanwei.cn/api/Storge/Viewable?ID=jobs/4fef2b8b-a407-4130-8045-ef2679f41084/output/main.hf"
    ];
    extensionRegisterInfo = {
        [this.getPath() + "/extensions/Sippreep.Extensions.NodeOffHack.js"]: ["Sippreep.Extensions.NodeOffHack.NodeOffHackExtension"],
    };
    loadExId = "Sippreep.Extensions.NodeOffHack.NodeOffHackExtension";
    viewerElementId = "viewer-div";
    async start() {
        await Sippreep.Initializer({ extensions: this.extensionRegisterInfo });
        this.viewer = new Sippreep.Viewing.Viewer3D(document.getElementById(this.viewerElementId), {});
        this.viewer.start();
        this.extension = await this.viewer.loadExtension(this.loadExId, {});
        await this.loadModel();
        return Promise.resolve();
    }
    async loadModel() {
        return new Promise((resolve, reject) => {
            let loadedNumber = 0;
            for (const url of this.modelUrls) {
                this.viewer.loadModel(url, {}, async (m) => {
                    loadedNumber++;
                    if (loadedNumber >= this.modelUrls.length) {
                        resolve();
                    }
                });
            }
        });
    }
    getPath() {
        let ans = window.location.href;
        return ans.substring(0, ans.lastIndexOf("/"));
    }
}

let main = new Main();
main.start().then(() => {
    console.warn("启动完成");
    setTimeout(() => {
        main.viewer.model.visibilityManager.setNodeOff([666,668,664], true);
        let s = main.viewer.getState();
        main.viewer.model.visibilityManager.setNodeOff([666], false);
        main.viewer.restoreState(s, undefined, false);
        alert("看不到楼顶说明state成功管理了off数据");
    }, 1000);


}, (e) => {
    console.warn("启动失败 "+e);
});